const fs = require("fs");
const path = require("path");
const argv = process.argv.slice(2);  

const targetPath = argv[0];

if (!targetPath) {
    console.log("请输入你要删除的文件或文件夹");
    process.exit(1);
}

function remove(filePath) {
    if (!fs.existsSync(filePath)) {
        console.log("不存在该文件或文件夹");
        return;
    }

    const stats = fs.statSync(filePath);
    
    if (stats.isFile()) {
        fs.unlinkSync(filePath);  
        console.log(`文件 ${filePath} 删除成功`);
    } 
    else if (stats.isDirectory()) {
        const files = fs.readdirSync(filePath);
        files.forEach(file => {
            
            const childPath = path.join(filePath, file);
            remove(childPath); 
        });
        fs.rmdirSync(filePath);
        console.log(`文件夹 ${filePath} 及其内容删除成功`); 
    }
}


remove(targetPath);